package com.example.jobback.controller.recruiter;

import com.example.jobback.dto.RecruiterRegisterDto;
import com.example.jobback.req.common.password.ResetPasswordReq;
import com.example.jobback.req.common.phone.ResetPhoneReq;
import com.example.jobback.req.recruiter.company.register.RecruiterRegisterReq;
import com.example.jobback.resp.recruiter.auth.RecruiterLoginResp;
import com.example.jobback.resp.recruiter.auth.VerifyCompanyRegisterStatusResp;
import com.example.jobback.result.Result;
import com.example.jobback.service.recruiter.RecruiterAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: RecruiterAuthController
 * @Description:招聘者-身份核验控制器
 * @Author: lhb
 * @Date: 2025/6/21
 */
@RestController
@RequestMapping("/recruiter/auth")
@Tag(name = "招聘者-身份核验控制器",description = "招聘者身份核验服务对应的相关接口")
public class RecruiterAuthController {
    private final RecruiterAuthService recruiterAuthService;

    public RecruiterAuthController(RecruiterAuthService recruiterAuthService) {
        this.recruiterAuthService = recruiterAuthService;
    }


//    @Operation(summary = "登录", description = "手机号登录")
//    @PostMapping("/loginByPhone")
//    @ApiResponse(description = "swagger显示不全，返回的data是{<br>" +
//            "   status：boolean,<br>" +
//            "   token：String<br>" +
//            "}status为true登录,false注册")
//    public Result<Object> loginByPhone(
//            @Parameter(description = "电话号码", required = true)
//            @Pattern(regexp = "^\\d{11}$", message = "电话号码必须是11位数字")
//            @RequestParam String phone,
//            @Parameter(description = "验证码", required = true)
//            @Pattern(regexp = "^\\d{4}$", message = "验证码必须是4位数字")
//            @RequestParam String code){
//        return recruiterAuthService.LoginByPhone(phone, code);
//    }


    @Operation(summary = "新招聘者登录", description = "手机号登录")
    @PostMapping("/login")
    @ApiResponse(description ="status为true时，直接登录。为false跳转公司注册")
    public Result<RecruiterLoginResp> login(
            @Parameter(description = "电话号码", required = true)
            @Pattern(regexp = "^\\d{11}$", message = "电话号码必须是11位数字")
            @RequestParam String phone,
            @Parameter(description = "密码", required = true)
            @RequestParam String password){
        return recruiterAuthService.login(phone, password);
    }

    @Operation(summary = "注册", description = "招聘端BOSS注册，要携带登录时返回的临时token")
    @PostMapping("/register")
    @ApiResponse(description = "除了状态码无返回值")
    public Result<Object> register(
            @Parameter(description = "电话号码", required = true)
            @Pattern(regexp = "^\\d{11}$", message = "电话号码必须是11位数字")
            @RequestParam String phone,
            @Parameter(description = "密码", required = true)
            @RequestParam String password
    ){
        return recruiterAuthService.register(phone,password);
    }

    @Operation(summary = "申请注册公司", description = "招聘端BOSS注册，要携带登录时返回的临时token")
    @PostMapping("/applyRegisterCompany")
    @ApiResponse(description = "除了状态码无返回值")
    public Result<Object> applyRegisterCompany(@Validated
                                   @RequestBody
                                   RecruiterRegisterReq req,
                                   @RequestHeader(value = "Authorization") String token){
        return recruiterAuthService.applyRegisterCompany(req,token);
    }

    @Operation(summary = "返回公司注册审核信息", description = "招聘端BOSS注册，返回审核信息，同样携带临时token")
    @GetMapping("/getVerifyMessage")
    @ApiResponse(description = "返回公司注册审核信息响应体")
    public Result<VerifyCompanyRegisterStatusResp> getVerifyMessage(
            @RequestHeader(value = "Authorization") String token){
        return recruiterAuthService.getVerifyMessage(token);
    }


    /**
     * @Description: 注册公司,跨服务接口
     * @Author lhb
     * @CreateTime 2025/5/17 20:25
     */
    @Operation(summary = "跨服务接口-注册公司", description = "后端跨服务接口,被调用方",hidden = true)
    @ApiResponse(description = "无")
    @PostMapping("/registerCompany")

    public Result<Object> registerCompany(@RequestBody
                                          RecruiterRegisterDto recruiterRegisterDto){
        return recruiterAuthService.registerCompany(recruiterRegisterDto);
    }


    @Operation(summary = "退出登录",description = "无")
    @PostMapping("/loginOut")
    public Result<Object> loginOut(){
        return recruiterAuthService.LoginOut();
    }

    @Operation(summary = "修改密码",description = "需要传递旧密码，建议修改后执行登出逻辑，重新登录")
    @PostMapping("/resetPassword")
    @ApiResponse(description = "")
    public Result<Object> resetPassword(@Validated
                                        @RequestBody
                                        ResetPasswordReq resetPasswordReq){
        return recruiterAuthService.resetPassword(resetPasswordReq);
    }

    @Operation(summary = "更换手机号",description = "需要传递旧密码，建议修改后执行登出逻辑，重新登录")
    @PostMapping("/resetPhone")
    @ApiResponse(description = "")
    public Result<Object> resetPhone(@Validated
                                     @RequestBody
                                     ResetPhoneReq resetPhoneReq){
        return recruiterAuthService.resetPhone(resetPhoneReq);
    }

}
